{% extends 'base.html' %}

{% block title %}小区报修{% endblock %}

{% block stylesheet %}
<style type="text/css">
.weui-tab__bd {
    box-sizing: border-box;
    height: 90%;
}
</style>
{% endblock %}

{% block content %}
  	<div class="weui-tab">
		<div class="weui-navbar">
		  <div class="weui-navbar__item weui_bar__item_on">

		  	<div class="weui-flex">
  		      <div class="weui-flex__item"><div class="placeholder">{{g.user.community.cmnt_name}}-小区报修</div></div>
		      <!-- <div class="weui-flex__item"><div class="placeholder"></div></div>
		      <div class="weui-flex__item"><div class="placeholder"></div></div> -->
		      <div class="weui-flex__item"><div class="placeholder"><a href="/newRepair" class="weui-btn weui-btn_mini weui-btn_primary">报修</a></div></div>
		    </div>

		  </div>
		</div>

      <div class="weui-tab__bd">
        <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">

          <div class="weui-panel weui-panel_access">
	        <div class="weui-panel__bd">
           {% if repairs %}
  	         {% for repair in repairs %}
            <div class="weui-media-box weui-media-box_appmsg" data-rprid="{{repair['id']}}">
            <div class="weui-media-box__hd">
              {% if '04' == repair.status %}
             <i class="weui-icon-success repair-icon_msg"></i>
              {% else %}
                {% if 0 == repair.urgency %}
                <i class="weui-icon-info repair-icon_msg"></i>
                {% elif 1 == repair.urgency %}
                <i class="weui-icon-warn repair-icon_msg-primary"></i>
                {% else %}
                <i class="weui-icon-warn repair-icon_msg"></i>
                {% endif %}
              {% endif %}
            </div>
            <div class="weui-media-box__bd">
              <h4 class="weui-media-box__title">{{repair['title']}}</h4>
              <p class="weui-media-box__desc">{{repair['content']|striptags}}</p>
            </div>
             </div>
  	         {% endfor %}
           {% else %}
              <div class="weui-loadmore weui-loadmore_line">
                <span class="weui-loadmore__tips">暂无数据</span>
              </div>
           {% endif %}

	        </div>

          {% if repairs %}
                 <div class="weui-panel__ft">
                  <a href="javascript:loadmore();" class="weui-cell weui-cell_access weui-cell_link">
                    <div class="weui-cell__bd">查看更多</div>
                    <span class="weui-cell__ft"></span>
                  </a>    
                 </div>
          {% endif %}

	      </div>

        </div>
      </div>

      <div class="weui-tabbar">
        <a href="/topics" class="weui-tabbar__item">
          <!-- <span class="weui-badge" style="position: absolute;top: -.4em;right: 1em;">8</span> -->
          <div class="weui-tabbar__icon">
            <img src="{{ url_for('static', filename='images/icon_nav_dialog.png') }}" alt="">
          </div>
          <p class="weui-tabbar__label">话题</p>
        </a>
        <a href="#" class="weui-tabbar__item weui-bar__item--on">
          <div class="weui-tabbar__icon">
            <img src="{{ url_for('static', filename='images/icon_nav_article.png') }}" alt="">
          </div>
          <p class="weui-tabbar__label">报修</p>
        </a>
        <a href="/discovery" class="weui-tabbar__item">
          <div class="weui-tabbar__icon">
            <img src="{{ url_for('static', filename='images/icon_nav_button.png') }}" alt="">
          </div>
          <p class="weui-tabbar__label">发现</p>
        </a>
        <a href="/auth/profile" class="weui-tabbar__item">
          <div class="weui-tabbar__icon">
            <img src="{{ url_for('static', filename='images/icon_nav_cell.png') }}" alt="">
          </div>
          <p class="weui-tabbar__label">我</p>
        </a>
      </div>
    </div>
{% endblock %}

{% block jsblock %}
//$(".weui-media-box.weui-media-box_appmsg").on('click', function(){
//   //alert($(this).data('rprid'))
//   $(location).attr('href', '/showRepair/'+$(this).data('rprid'));
//});

$(".weui-panel__bd").delegate(".weui-media-box.weui-media-box_appmsg","click",function(){
     $(location).attr('href', '/showRepair/'+$(this).data('rprid'));
});

function comingsoon() {
  $.toast("功能实现中...<br>敬请期待～", "text");
}

var page = 1;

function loadmore() {
    page++;

    $.ajax({
    type: 'GET',
    url: '/loadRepairs/'+page,
    success: function(data) {
          divHtml="";
           $.each(data['repairs'], function (n, repair) {
            var cate = "";
            var icon = "";
            if ('04' == repair['status']) {
              icon = ' <i class="weui-icon-success repair-icon_msg"></i>';
            }else {
              if(0 == repair['urgency']) {
                icon = '<i class="weui-icon-info repair-icon_msg"></i>';
              }else if (1 == repair['urgency']) {
                icon = '<i class="weui-icon-warn repair-icon_msg-primary"></i>';
              }else {
                icon = '<i class="weui-icon-warn repair-icon_msg"></i>';
              }

            } 
              divHtml = divHtml+ '<div class="weui-media-box weui-media-box_appmsg" data-rprid="' 
                               + repair['id'] + '">'
                               + '<div class="weui-media-box__hd">' + icon + '</div>'
                               + '<div class="weui-media-box__bd"><h4 class="weui-media-box__title">' 
                               + repair['title'] + '</h4>'
                               + '<p class="weui-media-box__desc">' + repair['content'] + '</p></div> </div>' ;

           });

           if(data['repairs'].length < 5 ) {
            divHtml = divHtml + '<div class="weui-loadmore weui-loadmore_line"> <span class="weui-loadmore__tips">没有更多数据</span> </div>';
             $(".weui-panel__ft").hide();
            }

           $(".weui-panel__bd").append(divHtml);

             },
    error: function(msg) {
          $.toast("获取失败请重试", "forbidden");
           page--;
      }
  });

}
{% endblock %}